﻿using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.EsgResearchProfileLogic;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.Tests.Helpers;
using System.Threading.Tasks;
using Xunit;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.CorporateDataLogic;
using Sustainalytics.SharedEntities.EsgResearch;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.Tests
{
    public class CoreEsgResearchProfileLogicTests
    {
        private readonly ICoreEsgSyncOrchestrator<EsgResearchProfile> coreEsgResearchProfileOrchestrator;

        private readonly ICoreEsgCompaniesIdsQuery coreEsgCompaniesIdsQuery;

        private readonly ICoreEsgResearchProfileQuery coreEsgResearchProfileQuery;

        public CoreEsgResearchProfileLogicTests()
        {
            TestLogger logger = new TestLogger();
            var container = SimpleInjectorConfig.Register(logger, TestConnectionStrings.GAConnectionStrings);

            coreEsgCompaniesIdsQuery = container.GetInstance<EsgCompaniesIdsQuery>();

            coreEsgResearchProfileQuery = container.GetInstance<EsgResearchProfileQuery>();
            coreEsgResearchProfileOrchestrator = container.GetInstance<EsgResearchProfileOrchestrator>();
        }

        [Fact]
        public async Task ResolveCoreEsgResearchProfiles()
        {
            var coreEsgCompaniesIds = await coreEsgCompaniesIdsQuery.GetAsync();

            var coreEsgResearchProfileEntities = coreEsgResearchProfileQuery.Get(coreEsgCompaniesIds.CompaniesWithActiveResearch);

            await coreEsgResearchProfileOrchestrator.OrchestrateAsync(coreEsgResearchProfileEntities, coreEsgCompaniesIds.InvalidatedCompanies);
        }
    }
}
